<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>添加员工</title>
    <link rel="stylesheet" href="/asset/layui/css/layui.css">
    <link rel="stylesheet" href="/asset/css/index.css">
    <link href="http://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <link rel="Shortcut Icon" href="cachet.ico">
    <script type="text/javascript" src="/asset/js/jquery-3.3.1.min.js"></script>
	<script src="/asset/layui/layui.js"></script>
    <script src="/asset/js/common.js"></script>
</head>
<body >
<div class="alert_bigbox">

	<form class="layui-form">
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>手机号码
              </label>
              <div class="layui-input-inline">
                 <div class="search">
			            <input type="text" name="username" id="username" class="layui-input" placeholder="请输入手机号码搜索">
			            <button type="button" id="search"></button>
			     </div>
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>手机号码为登陆账户
              </div>
          </div>
          
          
          <div class="layui-form-item layui-hide" id="userInfo">
              <label for="username" class="layui-form-label">
              </label>
              <div class="layui-input-inline">
              		<div>
	                    <div>
	                		 <img style="width: 45px;height: 45px;border-radius: 45px;" id="portrait" alt="" src="/asset/images/portrait.png">
	                	</div>
	                	<div style="width:45px;text-align:center;margin-top: 5px;font-size: 12px;" id="name">张三</div>
                	</div>
              </div>
          </div>
          
          <div class="layui-hide" id="userPasd">
	          <div class="layui-form-item">
	              <label for="password" class="layui-form-label">
	                  <span class="x-red">*</span>登陆密码
	              </label>
	              <div class="layui-input-inline">
	                  <input type="password" id="password" name="password" required="" lay-verify="password" autocomplete="off" class="layui-input">
	              </div>
	              <div class="layui-form-mid layui-word-aux">6-18个字符 </div>
	          </div>
	          <div class="layui-form-item">
	              <label for="password" class="layui-form-label">
	                  姓名
	              </label>
	              <div class="layui-input-inline">
	                  <input type="text" id="name" name="name"  autocomplete="off" class="layui-input">
	              </div>
	              <div class="layui-form-mid layui-word-aux">6-18个字符 </div>
	          </div>
 			  <div class="layui-form-item">
	                <label class="layui-form-label">性别</label>
	                <div class="layui-input-block">
				      <input type="radio" name="gender" value="MALE" title="男">
				      <input type="radio" name="gender" value="FEMALE" title="女">
				      <input type="radio" name="gender" value="UNKNOWN" title="未知" checked>
				    </div>
	          </div>
	          
	          <div class="layui-form-item">
                <label class="layui-form-label">部门</label>
                <div class="layui-input-inline">
                	<select name="orgId">
				        <option value="">请选择机构</option>
				        <#list orgs as item>
				        <option value="${item.organizationId}">${item.name}</option>
				        </#list>
				     </select>
                </div>
              </div>
	          
	          <div class="layui-form-item">
                <label class="layui-form-label">职务</label>
                <div class="layui-input-inline">
                    <input type="text" name="position" id="position" placeholder="请输入公司职务" value=""   autocomplete="off" class="layui-input">
                </div>
              </div>
	          
          </div>
          
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" lay-submit="">增加</button>
          </div>
      </form>

</div>

    <script>
    	var status = 0;
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;
          
          form.verify({  
		        username: [/^1\d{10}$/, "请输入正确的手机号"]  
		  });  
          
          $("#search").click(function(){
          	 var searchKey = $("#username").val();
          	 if(!searchKey){
          	 	layer.msg("请输入手机号码");
          	 	return false;
          	 }
          	 var myreg=/^1\d{10}$/;
          	 if (!myreg.test(searchKey)) {
          	 	layer.msg("请输入正确的手机号");
          	 	return false;
          	 }
          	 
          	 
          	 $.ajax({
      			type:"POST", 
      			url:"/staff/search.htm?searchKey="+searchKey,
      			success:function(result) {
		      		status = 1;
		      		if(result.code=='1'){
		      			
		      			$("#portrait").attr("src",result.data.portrait?result.data.portrait:'/asset/images/portrait.png');
		      			$("#name").html(result.data.name);
		      			$("#userInfo").removeClass("layui-hide")
		      			$("#userPasd").addClass("layui-hide")
		      		}else{
		      		 	$("#userPasd").removeClass("layui-hide")
		      		 	$("#userInfo").addClass("layui-hide")
		      		}
		      
		    	} 
		    }); 
          	 
          	 
          	 return false;
          })
          

          //监听提交
          form.on('submit(add)', function(data){
          	if(status ==0 ){
          		layer.msg("请点击搜索用户");
          	 	return false;
          	}
          
          	 var searchKey = $("#username").val();
          	 if(!searchKey){
          	 	layer.msg("请输入手机号码");
          	 	return false;
          	 }
          	 var myreg=/^1\d{10}$/;
          	 if (!myreg.test(searchKey)) {
          	 	layer.msg("请输入正确的手机号");
          	 	return false;
          	 }
          
          
            $.ajax({
      			type:"POST", 
      			url:"/staff/create.htm",
      			data:data.field,
      			success:function(result) {
		      
		      		if(result.code=='1'){
		      			layer.alert("增加成功", {icon: 6},function () {
			                // 获得frame索引
			                parent.document.getElementById('rightMain').contentWindow.location.reload(true);
			                var index = parent.layer.getFrameIndex(window.name);
			                parent.layer.close(index);
			            });
		      		}else{
		      		 	layer.msg(result.msg);
		      		}
		      
		    	 } 
		    }); 
            
            
            
            return false;
          });
          
        });
    </script>

</body>
</html>